//
//  HAODE
//
//  Created by panquanReabam.com on 15/9/23.
//  Copyright (c) 2015年 reabam.com. All rights reserved.
//

#import "BusinessOrderExtAddViewController.h"
#import "ZJSwitch.h"
#import "daogouview.h"
#import "MJRefresh.h"
#import "shouyinCell.h"
#import "huiyuandengjiViewController.h"
#import "shangpingview.h"
#import "peisongleibieViewController.h"
#import "ToResiduePayViewController.h"
#import "addhuiyuanViewController.h"
#import "huiyuanDetailsViewController.h"
#import "BusinessCouponDetailViewController.h"
#import "saoyisaoViewController.h"
#import "BusinessMemberAddressViewController.h"
#import "ClearFB.h"
@interface BusinessOrderExtAddViewController ()<MBProgressHUDDelegate,UIGestureRecognizerDelegate,UINavigationControllerDelegate,UITextFieldDelegate,UITextViewDelegate,UISearchBarDelegate,UIScrollViewDelegate,UITableViewDelegate,UITableViewDataSource,huiyuandengjiViewControllerDelegate>
@property (strong, nonatomic) NSString *areaValue;
@property (strong, nonatomic) NSString*cityValue;
@property (strong, nonatomic) NSString*GuideCode;
@property (strong, nonatomic) NSString*memberId;
@property (strong, nonatomic) NSString*isEarnest;
@property(nonatomic,retain)UIDatePicker* da;
@end

@implementation BusinessOrderExtAddViewController

{
    UISearchBar *search;
    HAODEsingleton* commdity;
    UIButton* sxBtn;
    UIButton*jiantouBtn;
    UIButton*cardBtn;
    float lastContentOffset;
    UITextField*searchTextField;
    UITextField*zhekoujineTextFied;
    UITextField*songhuoTextFied;
    UITextField*anzhuangTextFied;
    UIButton*daogouname;
    UIView*view;
    UIView*view1;
    shangpingview*shangpingView;
    UIScrollView*mainScroll;
    UIScrollView*MYmainScroll;
    UILabel*huiyuanname;
    UIButton *tureBtn;
    UILabel*dingdanhao1;
    BOOL saveAccount;
    UIButton *xuanze;
    UIButton*jiagemingxi1;
    UIButton*DiscountRateSatBtn;
    NSMutableArray* arrrss;
    NSMutableArray*DiscountRatecode ;
    NSMutableArray*DiscountRatecontent ;
    ZJSwitch *switch2;
    NSMutableArray*EarnestRatecode ;
    NSMutableArray*EarnestRatecontent ;
    NSMutableArray*InstallTypecode ;
    NSMutableArray*InstallTypecontent ;
    NSMutableArray*DeliveryTypecode ;
    NSMutableArray*DeliveryTypecontent ;
    UITextField*dinjinjineTextFied;
    UIButton*EarnestRateSatBtn;
    UILabel* weightke;
    UIView*view2;
    UIView*view3;
    UIView*view4;
    UIView*view5;
    UIView*view6;
    UITextView* tv;
    UILabel * label;
    UIImageView*imagess;
    UILabel*shengyuzhifujiage1;
    UIButton*anzhuangSatBtn;
    UIButton*peisongSatBtn;
    UIButton*jiantouBtn1;
    UIButton*jiantouBtn2;
    UIButton*jiantouBtn3;
    UIButton*jiantouBtn4;
    UIButton*jiantouBtn5;
    UIButton*jiantouBtn6;
    UIView* myToolBar;
    NSString*totalMoney;
    UILabel*youhuijine;
    UILabel*youhuiquanjine;
    UIButton*hejiMoney;
    NSString*jine;
    NSMutableArray*title ;
    NSMutableArray*couponId ;
    NSMutableArray*price ;
    UILabel*shoukuanxinxi;
    UILabel *lineLab1;
    NSMutableArray*couponIds ;
    NSMutableArray*prices ;
    UIImageView *_xianvi;
     NSMutableArray*hejiprices ;
    NSString* userToken;
}
@synthesize alt = alt;

-(void)BackAction:(UIButton *)sender{
    
    [self.navigationController popViewControllerAnimated:YES];
    //   [self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:0] animated:YES];
    
}
- (void)viewDidDisappear:(BOOL)animated

{
    
    [super viewDidDisappear:animated];
    
    
    
    self.navigationController.delegate = nil;
    
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    [[self rdv_tabBarController] setTabBarHidden:YES];
    self.navigationController.navigationBarHidden=NO;
        self.navigationController.navigationBar.barStyle = UIBaselineAdjustmentNone;
    UILabel *lineLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, 43,ScreenWidth, 1)];
    [lineLabel setBackgroundColor:[UIColor colorWithRed:238/255.0 green:238/255.0 blue:238/255.0 alpha:1]];
    lineLabel.alpha=1;
    [self.navigationController.navigationBar addSubview:lineLabel];
    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
    [[UINavigationBar appearance] setBarTintColor:Color];
    
    UIImage* backImage = [UIImage imageNamed:@"fanhui"];
    CGRect backframe = CGRectMake(0,0,30,30);
    UIButton* backButton= [[UIButton alloc] initWithFrame:backframe];
    [backButton setBackgroundImage:backImage forState:UIControlStateNormal];
    backButton.titleLabel.textAlignment=NSTextAlignmentLeft;
    [backButton addTarget:self action:@selector(BackAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    self.navigationItem.leftBarButtonItem = leftBarButtonItem;
    self.navigationController.delegate = self;
    
    self.navigationController.interactivePopGestureRecognizer.delegate = self;
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@""] forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.shadowImage =[[UIImage alloc] init];
    //会员信息
    
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    userToken = [user objectForKey:@"tokenId"];
    self.title=@"确认订单";
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                                     [UIColor blackColor],
                                                                     UITextAttributeTextColor,
                                                                     [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1],
                                                                     UITextAttributeTextShadowColor,
                                                                     [NSValue valueWithUIOffset:UIOffsetMake(0, 0)],
                                                                     UITextAttributeTextShadowOffset,
                                                                     [UIFont fontWithName:@"Helvetica Neue" size:tetlefot],
                                                                     UITextAttributeFont,nil]];
    commdity=[HAODEsingleton shared];
    
    if (commdity.userName!=nil ) {
        hejiprices=[[NSMutableArray alloc]init];
        [huiyuanname removeFromSuperview];
        [view removeFromSuperview];
        [sxBtn removeFromSuperview];
        [_xianvi removeFromSuperview];
        
        view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 300)];
        view.backgroundColor=zuiqianhuicolor;
        
        
        
        view1=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 80/2)];
        view1.backgroundColor=[UIColor whiteColor];
        [view addSubview:view1];
        
        
        UILabel *line1=[[UILabel alloc] initWithFrame:CGRectMake(0, 40, ScreenWidth, 0.35)];
        line1.backgroundColor=qianhuicolor;
        [view addSubview:line1];
        UILabel *line2=[[UILabel alloc] initWithFrame:CGRectMake(0, 40+10-0.35, ScreenWidth, 0.35)];
        line2.backgroundColor=qianhuicolor;
        [view addSubview:line2];
        UILabel* duogou=[[UILabel alloc]initWithFrame:CGRectMake(15, 25/2, 40, 15)];
        duogou.text=[NSString stringWithFormat:@"员工"];
        duogou.textColor=zhonghuiColor;
        duogou.font=[UIFont systemFontOfSize:15];
        [view addSubview:duogou];
        
    
        
        
        NSUserDefaults *user1 = [NSUserDefaults standardUserDefaults];
        NSString* UserName = [user1 objectForKey:@"userName"];
        self.GuideCode = [user1 objectForKey:@"UserCode"];
        daogouname=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth-200,  25/2,180,15)];
        [daogouname setTitle:UserName forState:UIControlStateNormal];
        daogouname.titleLabel.font=[UIFont systemFontOfSize:15];
        daogouname.titleLabel.textAlignment=NSTextAlignmentRight;
        daogouname.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
        //[daogouname addTarget:self action:@selector(xuanzhidaogou:) forControlEvents:UIControlEventTouchUpInside];
        [daogouname setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [view addSubview:daogouname];
        
        
        
        
        view2=[[UIView alloc]initWithFrame:CGRectMake(0, view1.bottom+10, ScreenWidth, 250/2)];
        view2.backgroundColor=[UIColor whiteColor];
        [view addSubview:view2];
        UILabel *line3=[[UILabel alloc] initWithFrame:CGRectMake(0, view2.bottom, ScreenWidth, 0.35)];
        line3.backgroundColor=qianhuicolor;
        [view addSubview:line3];
        UILabel *line4=[[UILabel alloc] initWithFrame:CGRectMake(0, view2.bottom+10-0.35, ScreenWidth, 0.35)];
        line4.backgroundColor=qianhuicolor;
        [view addSubview:line4];
        UIButton*jiantou = [[UIButton alloc]init];
        jiantou.frame = CGRectMake(ScreenWidth-55-10-13-13-8,50/2-5,8, 13);
        [jiantou setImage:[UIImage imageNamed:@"xiangzuo-.png"] forState:UIControlStateNormal];
        [jiantou addTarget:self action:@selector(edithuiyuan:) forControlEvents:UIControlEventTouchUpInside];
        [view2 addSubview:jiantou];
        NSString *s = [NSString stringWithFormat:@"%@(%@)",   commdity.userName, commdity.Phone];
        UIFont *font = [UIFont systemFontOfSize:16];
        CGSize size = CGSizeMake(320, 2000);
        CGSize labelsize = [s sizeWithFont:font constrainedToSize:size lineBreakMode:NSLineBreakByCharWrapping];
        huiyuanname=[[UILabel alloc]initWithFrame:CGRectMake(15, 0, labelsize.width+3, 50)];
        huiyuanname.text=[NSString stringWithFormat:@"%@(%@)",   commdity.userName, commdity.Phone];
        huiyuanname.textColor=[UIColor blackColor];
        huiyuanname.font=[UIFont systemFontOfSize:16];
        [view2 addSubview:huiyuanname];
        
        UIButton*suobtn=[[UIButton alloc]initWithFrame:CGRectMake(0, 10, ScreenWidth-70,60)];
        [suobtn addTarget:self action:@selector(edithuiyuan:) forControlEvents:UIControlEventTouchUpInside];
        [view2 addSubview:suobtn];
        
        UILabel *l=[[UILabel alloc] initWithFrame:CGRectMake(ScreenWidth-55-10-13,13,0.35, 30)];
        l.backgroundColor=qianhuicolor;
        [view2 addSubview:l];
        sxBtn = [[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth-55-10, 50/2-10, 55,25)];
        [sxBtn setTitle:@"修改" forState:UIControlStateNormal];
        [sxBtn setTitleColor:shenhuicolor forState:UIControlStateNormal];
        [sxBtn.layer setCornerRadius:1.0];
        sxBtn.titleLabel.font=[UIFont systemFontOfSize:14];
        [sxBtn.layer setBorderWidth:0.3];
        [sxBtn.layer setMasksToBounds:YES];
        CGColorSpaceRef colorSpace2 = CGColorSpaceCreateDeviceRGB();
        CGColorRef colorref2 = CGColorCreate(colorSpace2,(CGFloat[]){ 0, 0, 0, 0.3 });
        [sxBtn.layer setBorderColor:colorref2];//边框颜色
        [sxBtn addTarget:self action:@selector(list:) forControlEvents:UIControlEventTouchUpInside];
        [view2 addSubview:sxBtn];
        
        
        
        UIImageView*Seximage=[[UIImageView alloc]initWithFrame:CGRectMake(huiyuanname.right+19, 14, 20, 20)];
        if (![commdity.Sex isEqual:[NSNull null]]) {
            
            if ([commdity.Sex isEqualToString:@"男"]) {
                
                
                Seximage.image=[UIImage imageNamed:@"nan"];
                
            }else{
                
                Seximage.image=[UIImage imageNamed:@"nv"];
                
            }
            
            [view2 addSubview:Seximage];
            
        }
        
        
        _xianvi = [[UIImageView alloc]initWithFrame:CGRectMake(15,50, ScreenWidth-30, 0.5)];
        _xianvi.image=[UIImage imageNamed:@"hengxian"];
        [view2 addSubview:_xianvi];
        
        
        
        
        UILabel*shouhuoren=[[UILabel alloc]initWithFrame:CGRectMake(15,  _xianvi.bottom+12.5, 45, contenfot)];
        shouhuoren.text=@"收货人";
        shouhuoren.font= [UIFont systemFontOfSize:conten14fot];
        [shouhuoren setTextColor:zhonghuiColor];
        [view2 addSubview:shouhuoren];
        
        NSString *s121 =commdity.consigneeName;
        UIFont *font121 = [UIFont systemFontOfSize:conten14fot];
        CGSize size121 = CGSizeMake(ScreenWidth-60, 2000);
        CGSize labelsize121 = [s121 sizeWithFont:font121 constrainedToSize:size121 lineBreakMode:NSLineBreakByCharWrapping];
        UILabel*daogou1=[[UILabel alloc]initWithFrame:CGRectMake(shouhuoren.right, _xianvi.bottom+12.5,labelsize121.width, conten14fot)];
        daogou1.text=commdity.consigneeName;
        daogou1.font= [UIFont systemFontOfSize:conten14fot];
        [daogou1 setTextColor:shenhuicolor];
        [view2 addSubview:daogou1];
        
        UILabel*mendian=[[UILabel alloc]initWithFrame:CGRectMake(daogou1.right+18, _xianvi.bottom+12.5, 30, contenfot)];
        mendian.text=@"电话";
        mendian.font= [UIFont systemFontOfSize:conten14fot];
        [mendian setTextColor:zhonghuiColor];
        [view2 addSubview:mendian];
        UILabel*mendian1=[[UILabel alloc]initWithFrame:CGRectMake(mendian.right,_xianvi.bottom+12.5, 200, contenfot)];
        mendian1.text=commdity.consigneePhone;
        mendian1.font= [UIFont systemFontOfSize:conten14fot];
        [mendian1 setTextColor:shenhuicolor];
        [view2 addSubview:mendian1];
        
        
        UIButton*jiantou1 = [[UIButton alloc]init];
        jiantou1.frame = CGRectMake(ScreenWidth-30,80,8, 13);
        [jiantou1 setImage:[UIImage imageNamed:@"xiangzuo-.png"] forState:UIControlStateNormal];
        [jiantou1 addTarget:self action:@selector(edithuiyuan1:) forControlEvents:UIControlEventTouchUpInside];
        [view2 addSubview:jiantou1];
        UIButton*jiada1=[[UIButton alloc]initWithFrame:CGRectMake(150, 60, ScreenWidth,60)];
        [jiada1 addTarget:self action:@selector(edithuiyuan1:) forControlEvents:UIControlEventTouchUpInside];
        [view2 addSubview:jiada1];
        
        
        
        
        
        
        
        NSString *s1 =[NSString stringWithFormat:@"收货地址 %@",  commdity.consigneeAddr];
        UIFont *f1 = [UIFont systemFontOfSize:conten14fot];
        CGSize sizedizhi = CGSizeMake(ScreenWidth-60, 2000);
        CGSize labelsizedizhi = [s1 sizeWithFont:f1 constrainedToSize:sizedizhi lineBreakMode:NSLineBreakByCharWrapping];
        
        
        huiyuanname=[[UILabel alloc]initWithFrame:CGRectMake(15, shouhuoren.bottom+5, ScreenWidth-60, labelsizedizhi.height)];
        huiyuanname.text=[NSString stringWithFormat:@"收货地址 %@",  commdity.consigneeAddr];
        huiyuanname.textColor=shenhuicolor;
        huiyuanname.numberOfLines=2;
        huiyuanname.font=[UIFont systemFontOfSize:conten14fot];
        
        NSMutableAttributedString *AttributedSt = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"收货地址 %@",  commdity.consigneeAddr]];
        
        [AttributedSt addAttribute:NSFontAttributeName
         
                                value:[UIFont systemFontOfSize:conten14fot]
         
                                range:NSMakeRange(0, 4)];
        
        [AttributedSt addAttribute:NSForegroundColorAttributeName
         
                                value:zhonghuiColor
         
                                range:NSMakeRange(0, 4)];
        
        
        huiyuanname.attributedText = AttributedSt;

        [view2 addSubview:huiyuanname];
        
        
        
        
        
        self.memberId=commdity.memberId;
  
        view3=[[UIView alloc]initWithFrame:CGRectMake(0, view2.bottom+10, ScreenWidth, 45)];
        view3.backgroundColor=[UIColor whiteColor];
        [view addSubview:view3];
        
        
        UILabel*shangpingxinxi=[[UILabel alloc]initWithFrame:CGRectMake(15, 0, 80, 45)];
        shangpingxinxi.text=@"商品信息";
        shangpingxinxi.textColor=[UIColor blackColor];
        shangpingxinxi.font=[UIFont systemFontOfSize:15];
        [view3 addSubview:shangpingxinxi];
   
        
        
        
        
//        self.dealPriceArray
//        self.quantityArray
        for (int i = 0; i<self.dealPriceArray.count; i++) {
            double d;
            double d1;
            d =[self.dealPriceArray[i]doubleValue];
            d1 =[self.quantityArray[i]doubleValue];
            [hejiprices addObject:[NSString stringWithFormat:@"%f",d*d1]];
            
        }
        
        totalMoney = [hejiprices valueForKeyPath:@"@sum.floatValue"];
        jine= [hejiprices valueForKeyPath:@"@sum.floatValue"];
       
        
        
        
        NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
        [numberFormatter setPositiveFormat:@"###,##0.00;"];
        NSString *formattedNumberString = [numberFormatter stringFromNumber:[NSNumber numberWithDouble:totalMoney.doubleValue]];
         NSNumber *sum11 = [self.quantityArray valueForKeyPath:@"@sum.floatValue"];
        weightke=[[UILabel alloc]initWithFrame:CGRectMake(ScreenWidth-250, 0, 230, 45)];
        weightke.text=[NSString  stringWithFormat:@"共 %@ 件,   ￥%@",sum11, formattedNumberString];
        weightke.textColor = [UIColor colorWithRed:5.00/255.0 green:18.0/255.0 blue:40.00/255.0 alpha:1];
        weightke.textAlignment = NSTextAlignmentRight;
        weightke.font = [UIFont systemFontOfSize:16];
        
        
        
        NSMutableAttributedString *AttributedStr2 = [[NSMutableAttributedString alloc]initWithString:[NSString  stringWithFormat:@"共 %@ 件,   ￥%@",sum11, formattedNumberString]];
        [AttributedStr2 addAttribute:NSFontAttributeName
         
                               value:[UIFont systemFontOfSize:13.0]
         
                               range:NSMakeRange(0, 8)];
        
        [AttributedStr2 addAttribute:NSForegroundColorAttributeName
         
                               value:zhonghuiColor
         
                               range:NSMakeRange(0, 8)];
        
        
        weightke.attributedText = AttributedStr2;
        [view3 addSubview:weightke];
        
        
        
        UILabel *lineLabel1=[[UILabel alloc] initWithFrame:CGRectMake(15, 45-0.35, ScreenWidth-30, 0.35)];
        lineLabel1.backgroundColor=qianhuicolor;
        [view3 addSubview:lineLabel1];
        

        if (self.headImageFullArray.count>0) {
            
            for (int i = 0; i<self.headImageFullArray.count; i++) {
                
                shangpingView = [[shangpingview alloc]initWithFrame:CGRectMake(0, view3.bottom+(120*i), ScreenWidth, 120)];
                shangpingView.backgroundColor=[UIColor whiteColor];
                [shangpingView.headImageFull setImageWithURL:[self.headImageFullArray objectAtIndex:i]  placeholderImage:[UIImage imageNamed:@""]];
                [shangpingView.headImageFull.layer setCornerRadius:6.0];
                [shangpingView.headImageFull.layer setBorderWidth:0.3];
                [shangpingView.headImageFull.layer setMasksToBounds:YES];
                CGColorSpaceRef colorSpace2 = CGColorSpaceCreateDeviceRGB();
                CGColorRef colorref2 = CGColorCreate(colorSpace2,(CGFloat[]){ 0, 0, 0, 0.3 });
                [shangpingView.headImageFull.layer setBorderColor:colorref2];//边框颜色
                
                shangpingView.itemName.text=[NSString stringWithFormat:@"%@%@",[self.itemCodeArray objectAtIndex:i],[self.itemNameArray objectAtIndex:i]];
                
                shangpingView.quantity.text=[NSString stringWithFormat:@"数量 %@",[self.quantityArray objectAtIndex:i]];
                
                NSMutableAttributedString *AttributedStr1 = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"数量 %@",[self.quantityArray objectAtIndex:i]]];
                
                [AttributedStr1 addAttribute:NSFontAttributeName
                 
                                       value:[UIFont systemFontOfSize:contenfot]
                 
                                       range:NSMakeRange(0, 3)];
                
                [AttributedStr1 addAttribute:NSForegroundColorAttributeName
                 
                                       value:zhonghuiColor
                 
                                       range:NSMakeRange(0, 3)];
                
                
                shangpingView.quantity.attributedText = AttributedStr1;
                
                
                NSNumber*Total =[self.dealPriceArray objectAtIndex:i];
                
                NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
                [numberFormatter setPositiveFormat:@"###,##0.00;"];
                NSString *formattedNumberString = [numberFormatter stringFromNumber:[NSNumber numberWithDouble:Total.doubleValue]];
                shangpingView.dealPrice.text=[NSString stringWithFormat:@"¥ %@",formattedNumberString];
                shangpingView.dealPrice.textColor=hongsecolor;
                shangpingView.itemType.text=[NSString stringWithFormat:@"%@",[self.specNameArray objectAtIndex:i]];
                
                NSMutableAttributedString *AttributedStr12 = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"¥ %@",formattedNumberString]];
                
                [AttributedStr12 addAttribute:NSFontAttributeName
                 
                                       value:[UIFont systemFontOfSize:14]
                 
                                       range:NSMakeRange(0, 1)];
                
                [AttributedStr12 addAttribute:NSForegroundColorAttributeName
                 
                                       value:hongsecolor
                 
                                       range:NSMakeRange(0, 1)];
                
                
                shangpingView.dealPrice.attributedText = AttributedStr12;
                
                
                if (i==self.quantityArray.count-1) {
                    UILabel *lineLabel1=[[UILabel alloc] initWithFrame:CGRectMake(0, 120-0.35, ScreenWidth, 0.35)];
                    lineLabel1.backgroundColor=qianhuicolor;
                    [shangpingView addSubview:lineLabel1];
                }else{
                    UILabel *lineLabel1=[[UILabel alloc] initWithFrame:CGRectMake(15, 120-0.35, ScreenWidth-30, 0.35)];
                    lineLabel1.backgroundColor=qianhuicolor;
                    [shangpingView addSubview:lineLabel1];
                    
                    
                }
                
                [view addSubview:shangpingView];
                
            }
            
        }
        
        
        
        
        lineLab1=[[UILabel alloc] initWithFrame:CGRectMake(0, shangpingView.bottom+10-0.35, ScreenWidth, 0.35)];
        lineLab1.backgroundColor=qianhuicolor;
        [view addSubview:lineLab1];
        
        
        shoukuanxinxi=[[UILabel alloc]initWithFrame:CGRectMake(0, shangpingView.bottom+10, ScreenWidth, 45)];
        shoukuanxinxi.text=@"    收款信息";
        shoukuanxinxi.textColor=[UIColor blackColor];
        shoukuanxinxi.layer.borderColor = LineColor.CGColor;
        shoukuanxinxi.backgroundColor=[UIColor whiteColor];
        shoukuanxinxi.font=[UIFont systemFontOfSize:15];
        [view addSubview:shoukuanxinxi];
        
        view.frame=CGRectMake(0, 0, ScreenWidth, shoukuanxinxi.bottom);
        _table.tableHeaderView=view;
        
        
        
        
        
    }
    
    
    
    //配送和提货
    
    if (commdity.content!=nil ) {
        
        if ([commdity.sat isEqualToString:@"InstallType"]) {
            
            
            [anzhuangSatBtn setTitle:commdity.content forState:UIControlStateNormal];
        }
    }
    if (commdity.content1!=nil ) {
        
        if ([commdity.sat isEqualToString:@"DeliveryType"]) {
            
            [peisongSatBtn setTitle:commdity.content1 forState:UIControlStateNormal];
        }}
    
    
    //折扣
    
    if (commdity.content2!=nil ) {
        
        if ([commdity.sat isEqualToString:@"DiscountRate"]) {
            
            [DiscountRateSatBtn setTitle:commdity.content2 forState:UIControlStateNormal];
            
            double d1 = [totalMoney doubleValue];
            double d2 = [commdity.DiscountRatecode doubleValue];
            
            
            
            if (d2==0) {
                
                zhekoujineTextFied.text=[NSString stringWithFormat:@"%.2f",d1*d2];
                
                
                double d1;
                NSNumber *sum = [prices valueForKeyPath:@"@sum.floatValue"];
                double d2;
                double d3;
                d1=sum.doubleValue;
                d2=totalMoney.doubleValue;
                d3=zhekoujineTextFied.text.doubleValue;
                
                
                [self youhuijiehouduoshao:[NSString stringWithFormat:@"%.2f",d2-d1-d3]];
                
                
                
            }else {
                
                zhekoujineTextFied.text=[NSString stringWithFormat:@"%.2f",d1*(1-d2)];
                
                
                double d1;
                NSNumber *sum = [prices valueForKeyPath:@"@sum.floatValue"];
                double d2;
                double d3;
                d1=sum.doubleValue;
                d2=totalMoney.doubleValue;
                d3=zhekoujineTextFied.text.doubleValue;
                
                
                [self youhuijiehouduoshao:[NSString stringWithFormat:@"%.2f",d2-d1-d3]];
                
                
                
                
            }
            
            
        }
    }
    
    
    
    if (commdity.content3!=nil ) {
        
        if ([commdity.sat isEqualToString:@"EarnestRate"]) {
            
            [EarnestRateSatBtn setTitle:commdity.content3 forState:UIControlStateNormal];
            double d1 = [jine doubleValue];
            double d2 = [commdity.EarnestRatecode doubleValue];
            
            if (d2==0) {
                
                dinjinjineTextFied.text=[NSString stringWithFormat:@"%.2f",d1*d2];
                
                
                
            }else {
                
                dinjinjineTextFied.text=[NSString stringWithFormat:@"%.2f",d1*d2];
                
                
            }
            
            
        }}
    
    
    
    [self heji];
    
}
- (void)textFieldDidBeginEditing:(UITextField *)textField{
    
    if (textField.tag == 1)
    {
        
        [DiscountRateSatBtn setTitle:@"自定义" forState:UIControlStateNormal];
        
        
        double d1 = [totalMoney doubleValue];
        double d2 = [zhekoujineTextFied.text doubleValue];
        
        if (d2==0) {
            
            
            [self youhuijiehouduoshao:[NSString stringWithFormat:@"%.2f",d1-d2]];
            
            
            
        }else {
            
            
            [self youhuijiehouduoshao:[NSString stringWithFormat:@"%.2f",d1-d2]];
            
            
        }
        
        [self heji];
        if ( [textField.text intValue]==0) {
            zhekoujineTextFied.text=@"";
        }
        
        [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
        _table .frame =CGRectMake(0, -100, ScreenWidth, ScreenHeight);
        [UIView commitAnimations];
        
        
    }
    if (textField.tag == 2)
    {
        
        
        
        
        if ([self.isEarnest isEqualToString:@"Y"]) {
            [dinjinjineTextFied setUserInteractionEnabled:YES];
            [EarnestRateSatBtn setTitle:@"自定义" forState:UIControlStateNormal];
            
            [self heji];
            if ( [textField.text intValue]==0) {
                dinjinjineTextFied.text=@"";
            }
            
        }
        
        
        [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
        _table .frame =CGRectMake(0, -150, ScreenWidth, ScreenHeight);
        [UIView commitAnimations];
        
        
        
    }
    if (textField.tag == 3)
    { [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
        _table .frame =CGRectMake(0, -150, ScreenWidth, ScreenHeight);
        [UIView commitAnimations];
        
        
    }
    if (textField.tag == 4)
    { [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
        _table .frame =CGRectMake(0, -150, ScreenWidth, ScreenHeight);
        [UIView commitAnimations];
        
        
    }
    
    
}

- (void)textFieldDidChange:(UITextField *) TextField{
    
    if (TextField.tag == 1)
        
    {
        if (TextField.text.intValue<=totalMoney.intValue) {
            
            
            if (0<=TextField.text.intValue&&TextField.text.length<99)
            {
                
                
                [DiscountRateSatBtn setTitle:@"自定义" forState:UIControlStateNormal];
                
                
                
                double d2 = [zhekoujineTextFied.text doubleValue];
                
                if (d2==0) {
                    
                    double d1;
                    NSNumber *sum = [prices valueForKeyPath:@"@sum.floatValue"];
                    double d2;
                    double d3;
                    d1=sum.doubleValue;
                    d2=totalMoney.doubleValue;
                    d3=zhekoujineTextFied.text.doubleValue;
                    
                    
                    [self youhuijiehouduoshao:[NSString stringWithFormat:@"%.2f",d2-d1-d3]];
                    
                    [self heji];
                    
                }else {
                    
                    
                    double d1;
                    NSNumber *sum = [prices valueForKeyPath:@"@sum.floatValue"];
                    double d2;
                    double d3;
                    d1=sum.doubleValue;
                    d2=totalMoney.doubleValue;
                    d3=zhekoujineTextFied.text.doubleValue;
                    
                    
                    [self youhuijiehouduoshao:[NSString stringWithFormat:@"%.2f",d2-d1-d3]];
                    
                    [self heji];
                    
                    
                }
                
                
                
            }
            
        }else{
            
            [self showAlertMessage:@"整单折扣金额不能低于商品总价！"];
            TextField.text=@"";
            
            
        }
        
        
        
        
        
    }
    
    
    
    if (TextField.tag == 2)
        
    {
        
        
        if (0<=TextField.text.intValue&&TextField.text.length<99)
        {
            //            [self heji];
            if (TextField.text.intValue<=jine.intValue) {
                commdity.EarnestRatecode=@"0";
                [EarnestRateSatBtn setTitle:@"自定义" forState:UIControlStateNormal];
                
                NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
                [numberFormatter setPositiveFormat:@"###,##0.00;"];
                NSString *formattedNumberString = [numberFormatter stringFromNumber:[NSNumber numberWithDouble:TextField.text.doubleValue]];
                
               
                  [self priceStr:formattedNumberString];
                
                //               if ( [dinjinjineTextFied.text intValue]==0) {
                //                   dinjinjineTextFied.text=@"";
                //               }
                
            }else{
                
                [self showAlertMessage:@"定金金额不能低于优惠后的总价！"];
                TextField.text=@"";
                
            }
            
        }
        
        
    }
    
}



-(void)youhuijiehouduoshao:(NSString *)formattedNumberString{
    
    
    [youhuijine removeFromSuperview];
    
    jine=formattedNumberString;
    NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
    [numberFormatter setPositiveFormat:@"###,##0.00;"];
    NSString *formattedNumberString1 = [numberFormatter stringFromNumber:[NSNumber numberWithDouble:formattedNumberString.doubleValue]];
    
    youhuijine=[[UILabel alloc]initWithFrame:CGRectMake(15, 135-90, ScreenWidth-40, 45)];
    youhuijine.text=[NSString stringWithFormat:@"优惠后金额¥%@" ,formattedNumberString1];
    youhuijine.textColor=[UIColor blackColor];
    youhuijine.textAlignment = NSTextAlignmentRight;
    NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"优惠后金额 ¥ %@" ,formattedNumberString1]];
    
    [AttributedStr addAttribute:NSFontAttributeName
     
                          value:[UIFont systemFontOfSize:14.0]
     
                          range:NSMakeRange(0, 8)];
    
    [AttributedStr addAttribute:NSForegroundColorAttributeName
     
                          value:zhonghuiColor
     
                          range:NSMakeRange(0, 8)];
    
    
    youhuijine.attributedText = AttributedStr;
    [view4 addSubview:youhuijine];
    
    
    
}




-(void)xuanze:(UIButton*)sender
{
    
    saveAccount=!saveAccount;
    if (saveAccount) {
        
        [sender setImage:[UIImage imageNamed:@"gous"] forState:UIControlStateNormal];
        youhuiquanjine=[[UILabel alloc]initWithFrame:CGRectMake(xuanze.right+90, 45, 80, 45)];
        youhuiquanjine.text=@"¥ 0";
        youhuiquanjine.textColor=hongsecolor;
        youhuiquanjine.font=[UIFont systemFontOfSize:16];
        [view4 addSubview:youhuiquanjine];
        
    }
    else
    {
        
        [youhuiquanjine removeFromSuperview];
        [sender setImage:[UIImage imageNamed:@"quans"] forState:UIControlStateNormal];
        
        
        
        
        
    }
    
    
}
-(void)heji{
    
    
    
    
    if ([self.isEarnest isEqualToString:@"Y"]) {
        
        double d1 = [jine doubleValue];
        
        if ([commdity.content3 isEqualToString:@"自定义"] ) {
            
            
            
        }else{
            double d2 = [commdity.EarnestRatecode doubleValue];
            dinjinjineTextFied.text=[NSString stringWithFormat:@"%.2f",d1*d2];
            
            
        }
        
   
        NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
        [numberFormatter setPositiveFormat:@"###,##0.00;"];
        NSString *formattedNumberString = [numberFormatter stringFromNumber:[NSNumber numberWithDouble:dinjinjineTextFied.text.doubleValue]];
        
        [self priceStr:formattedNumberString];
        
        
    }
    
    
    
    
    if ([self.isEarnest isEqualToString:@"N"]) {
        
        NSString *subString2 = [youhuijine.text substringFromIndex:8];       //@"2345"
        [self priceStr:subString2];
    }
    
}
- (void)secondViewController:(huiyuandengjiViewController *)secondViewController
                  updateText:(NSString *)text
{
    
    
    commdity.memberId=text;
    [self jiazaiyouhuiquan];
}

- (void)jiazaiyouhuiquan
{
    price=[[NSMutableArray alloc]init];
    title=[[NSMutableArray alloc]init];
    couponId=[[NSMutableArray alloc]init];
    couponIds =[[NSMutableArray alloc]init];
    prices =[[NSMutableArray alloc]init];
    if (commdity.userName!=nil ) {
        
        
        NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
        NSString* Token = [user objectForKey:@"tokenId"];
        if (Token ==nil) {
            Token=@"dd";
        }
        NSMutableDictionary *param = [NSMutableDictionary new];
        [param setValue:Token forKey:@"tokenId"];
        
        [param setValue:commdity.memberId forKey:@"memberId"];
        [param setValue:totalMoney forKey:@"orderAmt"];
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        
        NSLog(@"-------000000000000000----%@", param);
        [HttpRequest requestData:@"Business/Coupon/getAvailableList" params:param success:^(BOOL isSuccess, SeverData *severDataDict) {
            if (isSuccess) {
                NSLog(@"-------000000000000000----%@", severDataDict.dataDict);
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                    
                    
                    NSMutableArray* arrr=[[NSMutableArray alloc]init];
                    arrr=[severDataDict.dataDict objectForKey:@"DataLine"];
                    
                    
                    for (NSDictionary* dicc in arrr )
                    {
                        [title addObject:[dicc valueForKey:@"title"]];
                        [couponId addObject:[dicc valueForKey:@"couponId"]];
                        [price addObject:[dicc valueForKey:@"price"]];
                        
                        
                        
                    }
                    [_table reloadData];
                    
                    
                    
                }else{
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    [Global showTextHudSub:requestResultStr view:self.view];
                }
                
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                NSLog(@"aaaaaaaa%@",severDataDict.dataDict);
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
            
        }];
        
        
    }
    
}

- (void)viewDidLoad
{
    
    [super viewDidLoad];
    
    
    commdity=[HAODEsingleton shared];
    commdity.addhuiyuanViewController =@"选择";
    
    self.isEarnest=@"N";
    InstallTypecode=[[NSMutableArray alloc]init];
    InstallTypecontent=[[NSMutableArray alloc]init];
    DeliveryTypecode=[[NSMutableArray alloc]init];
    DeliveryTypecontent=[[NSMutableArray alloc]init];
    EarnestRatecode=[[NSMutableArray alloc]init];
    EarnestRatecontent=[[NSMutableArray alloc]init];
    DiscountRatecode=[[NSMutableArray alloc]init];
    DiscountRatecontent=[[NSMutableArray alloc]init];
    hejiprices=[[NSMutableArray alloc]init];
    
    _table.delegate=self;
    _table.dataSource=self;
    [self.view addSubview:_table];
    _table.separatorStyle=UITableViewCellSeparatorStyleNone;
    
    

    
    myToolBar=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, viewheight)];
    myToolBar.backgroundColor=jianpancolor;
    UIButton*  tubtnDone=[[UIButton alloc]initWithFrame:CGRectMake(logoX,logoY, logoheight, logowidth)];
    [tubtnDone setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    [tubtnDone addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
    [myToolBar addSubview:tubtnDone];
    UIButton*btnDone111=[[UIButton alloc]initWithFrame:CGRectMake(myToolBar.frame.size.width - 55, 12, 40, 16)];
    [btnDone111 setTitle:@"确定" forState:UIControlStateNormal];
    [btnDone111 setTitleColor:jianpancolor1 forState:UIControlStateNormal];
    btnDone111 .titleLabel .font=[UIFont systemFontOfSize:daxiao];
    [btnDone111 addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
    [myToolBar addSubview:btnDone111];
    myToolBar.alpha=alp;
    UIButton* dabtn=[[UIButton alloc]initWithFrame:CGRectMake(myToolBar.frame.size.width-60, 0, 60, 40)];
    [dabtn addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
    [myToolBar addSubview:dabtn];
    
//    sxBtn = [[UIButton alloc] initWithFrame:CGRectMake(30, 0.0, 30, 30)];
//    [sxBtn setImage:[UIImage imageNamed:@"tianjia"] forState:UIControlStateNormal];
//    [sxBtn addTarget:self action:@selector(addhuiyuan1:) forControlEvents:UIControlEventTouchUpInside];
//    UIBarButtonItem* myBtnBtn1 = [[UIBarButtonItem alloc] initWithCustomView:sxBtn];
//    self.navigationItem.rightBarButtonItem = myBtnBtn1;
    
    
    view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 300)];
    view.backgroundColor=zuiqianhuicolor;
    
    view1=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 80/2)];
    view1.backgroundColor=[UIColor whiteColor];
    [view addSubview:view1];
    
    
    UILabel *line1=[[UILabel alloc] initWithFrame:CGRectMake(0, 40, ScreenWidth, 0.35)];
    line1.backgroundColor=qianhuicolor;
    [view addSubview:line1];
    UILabel *line2=[[UILabel alloc] initWithFrame:CGRectMake(0, 40+10-0.35, ScreenWidth, 0.35)];
    line2.backgroundColor=qianhuicolor;
    [view addSubview:line2];
    UILabel* duogou=[[UILabel alloc]initWithFrame:CGRectMake(15, 25/2, 40, 15)];
    duogou.text=[NSString stringWithFormat:@"员工"];
    duogou.textColor=zhonghuiColor;
    duogou.font=[UIFont systemFontOfSize:contenfot];
    [view addSubview:duogou];
    
    view2=[[UIView alloc]initWithFrame:CGRectMake(0, view1.bottom+10, ScreenWidth, 70)];
    view2.backgroundColor=[UIColor whiteColor];
    [view addSubview:view2];
    UILabel *line3=[[UILabel alloc] initWithFrame:CGRectMake(0, view2.bottom, ScreenWidth, 0.35)];
    line3.backgroundColor=qianhuicolor;
    [view addSubview:line3];
    UILabel *line4=[[UILabel alloc] initWithFrame:CGRectMake(0, view2.bottom+10-0.35, ScreenWidth, 0.35)];
    line4.backgroundColor=qianhuicolor;
    [view addSubview:line4];
    
    
    NSUserDefaults *user1 = [NSUserDefaults standardUserDefaults];
    NSString* UserName = [user1 objectForKey:@"userName"];
    self.GuideCode = [user1 objectForKey:@"UserCode"];
    daogouname=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth-200,  25/2,180,15)];
    [daogouname setTitle:UserName forState:UIControlStateNormal];
    daogouname.titleLabel.font=[UIFont systemFontOfSize:contenfot];
    daogouname.titleLabel.textAlignment=NSTextAlignmentRight;
    daogouname.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    //[daogouname addTarget:self action:@selector(xuanzhidaogou:) forControlEvents:UIControlEventTouchUpInside];
    [daogouname setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [view addSubview:daogouname];
    
    
    commdity=[HAODEsingleton shared];
    
    huiyuanname=[[UILabel alloc]initWithFrame:CGRectMake(15, 0, ScreenWidth-30, 40)];
    huiyuanname.text=@"会员信息...";
    huiyuanname.textColor=zhonghuiColor;
    huiyuanname.center=view2.center;
    huiyuanname.numberOfLines=2;
    huiyuanname.font=[UIFont systemFontOfSize:contenfot];
    [view addSubview:huiyuanname];
    
    UILabel *l=[[UILabel alloc] initWithFrame:CGRectMake(ScreenWidth-80,18,0.35, 35)];
    l.backgroundColor=qianhuicolor;
    [view2 addSubview:l];
    sxBtn = [[UIButton alloc] initWithFrame:CGRectMake( ScreenWidth-65, 23, 45,25)];
    [sxBtn setTitle:@"选择" forState:UIControlStateNormal];
    [sxBtn setTitleColor:shenhuicolor forState:UIControlStateNormal];
    [sxBtn.layer setCornerRadius:1.0];
    sxBtn.titleLabel.font=[UIFont systemFontOfSize:14];
    [sxBtn.layer setBorderWidth:0.3];
    [sxBtn.layer setMasksToBounds:YES];
    CGColorSpaceRef colorSpace2 = CGColorSpaceCreateDeviceRGB();
    CGColorRef colorref2 = CGColorCreate(colorSpace2,(CGFloat[]){ 0, 0, 0, 0.3 });
    [sxBtn.layer setBorderColor:colorref2];//边框颜色
    [sxBtn addTarget:self action:@selector(list:) forControlEvents:UIControlEventTouchUpInside];
    [view2 addSubview:sxBtn];
    
    _da = [[UIDatePicker alloc] init];
    [_da addTarget:self action:@selector(dateChanged:) forControlEvents:UIControlEventValueChanged];
    _da.datePickerMode = UIDatePickerModeDateAndTime;
    _da.backgroundColor=[UIColor whiteColor];
    
    view3=[[UIView alloc]initWithFrame:CGRectMake(0, view2.bottom+10, ScreenWidth, 45)];
    view3.backgroundColor=[UIColor whiteColor];
    [view addSubview:view3];
                
                
    UILabel*shangpingxinxi=[[UILabel alloc]initWithFrame:CGRectMake(15, 0, 80, 45)];
    shangpingxinxi.text=@"商品信息";
    shangpingxinxi.textColor=[UIColor blackColor];
    shangpingxinxi.font=[UIFont systemFontOfSize:sixteenORfifteenFot];
    [view3 addSubview:shangpingxinxi];
                
                
    for (int i = 0; i<self.dealPriceArray.count; i++) {
        double d;
        double d1;
        d =[self.dealPriceArray[i]doubleValue];
        d1 =[self.quantityArray[i]doubleValue];
        [hejiprices addObject:[NSString stringWithFormat:@"%f",d*d1]];
        
    }
    
    totalMoney = [hejiprices valueForKeyPath:@"@sum.floatValue"];
    jine= [hejiprices valueForKeyPath:@"@sum.floatValue"];
    
    
    NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
    [numberFormatter setPositiveFormat:@"###,##0.00;"];
    NSString *formattedNumberString = [numberFormatter stringFromNumber:[NSNumber numberWithDouble:totalMoney.doubleValue]];
    
    
     NSNumber *sum11 = [self.quantityArray valueForKeyPath:@"@sum.floatValue"];
    weightke=[[UILabel alloc]initWithFrame:CGRectMake(ScreenWidth-250, 0, 230, 45)];
    weightke.text=[NSString  stringWithFormat:@"共 %@ 件   ￥%@",sum11, formattedNumberString];
    weightke.textColor = [UIColor colorWithRed:5.00/255.0 green:18.0/255.0 blue:40.00/255.0 alpha:1];
    weightke.textAlignment = NSTextAlignmentRight;
    weightke.font = [UIFont systemFontOfSize:16];
    
    
    
    NSMutableAttributedString *AttributedStr2 = [[NSMutableAttributedString alloc]initWithString:[NSString  stringWithFormat:@"共 %@ 件   ￥%@",sum11, formattedNumberString]];
    [AttributedStr2 addAttribute:NSFontAttributeName
     
                           value:[UIFont systemFontOfSize:13.0]
     
                           range:NSMakeRange(0, 7)];
    
    [AttributedStr2 addAttribute:NSForegroundColorAttributeName
     
                           value:zhonghuiColor
     
                           range:NSMakeRange(0, 7)];
    
    
    weightke.attributedText = AttributedStr2;
    [view3 addSubview:weightke];
    
    
    
    UILabel *lineLabel1=[[UILabel alloc] initWithFrame:CGRectMake(15, 45-0.35, ScreenWidth-30, 0.35)];
    lineLabel1.backgroundColor=qianhuicolor;
    [view3 addSubview:lineLabel1];
    
    
    
    
    
    if (self.headImageFullArray.count>0) {
        
        for (int i = 0; i<self.headImageFullArray.count; i++) {
            
            shangpingView = [[shangpingview alloc]initWithFrame:CGRectMake(0, view3.bottom+(120*i), ScreenWidth, 120)];
            shangpingView.backgroundColor=[UIColor whiteColor];
            [shangpingView.headImageFull setImageWithURL:[self.headImageFullArray objectAtIndex:i]  placeholderImage:[UIImage imageNamed:@""]];
            [shangpingView.headImageFull.layer setCornerRadius:6.0];
            [shangpingView.headImageFull.layer setBorderWidth:0.3];
            [shangpingView.headImageFull.layer setMasksToBounds:YES];
            CGColorSpaceRef colorSpace2 = CGColorSpaceCreateDeviceRGB();
            CGColorRef colorref2 = CGColorCreate(colorSpace2,(CGFloat[]){ 0, 0, 0, 0.3 });
            [shangpingView.headImageFull.layer setBorderColor:colorref2];//边框颜色
            
            shangpingView.itemName.text=[NSString stringWithFormat:@"%@%@",[self.itemCodeArray objectAtIndex:i],[self.itemNameArray objectAtIndex:i]];
            
            shangpingView.quantity.text=[NSString stringWithFormat:@"数量 %@",[self.quantityArray objectAtIndex:i]];
            
            NSMutableAttributedString *AttributedStr1 = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"数量 %@",[self.quantityArray objectAtIndex:i]]];
            
            [AttributedStr1 addAttribute:NSFontAttributeName
             
                                   value:[UIFont systemFontOfSize:contenfot]
             
                                   range:NSMakeRange(0, 3)];
            
            [AttributedStr1 addAttribute:NSForegroundColorAttributeName
             
                                   value:zhonghuiColor
             
                                   range:NSMakeRange(0, 3)];
            
            
            shangpingView.quantity.attributedText = AttributedStr1;
            
            
            NSNumber*Total =[self.dealPriceArray objectAtIndex:i];
            
            NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
            [numberFormatter setPositiveFormat:@"###,##0.00;"];
            NSString *formattedNumberString = [numberFormatter stringFromNumber:[NSNumber numberWithDouble:Total.doubleValue]];
            shangpingView.dealPrice.text=[NSString stringWithFormat:@"¥ %@",formattedNumberString];
            shangpingView.dealPrice.textColor=hongsecolor;
            shangpingView.itemType.text=[NSString stringWithFormat:@"%@",[self.specNameArray objectAtIndex:i]];
            
            NSMutableAttributedString *AttributedStr12 = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"¥ %@",formattedNumberString]];
            
            [AttributedStr12 addAttribute:NSFontAttributeName
             
                                    value:[UIFont systemFontOfSize:14]
             
                                    range:NSMakeRange(0, 1)];
            
            [AttributedStr12 addAttribute:NSForegroundColorAttributeName
             
                                    value:hongsecolor
             
                                    range:NSMakeRange(0, 1)];
            
            
            shangpingView.dealPrice.attributedText = AttributedStr12;
            
            
            
            
            
                        if (i==self.quantityArray.count-1) {
                            UILabel *lineLabel1=[[UILabel alloc] initWithFrame:CGRectMake(0, 120-0.35, ScreenWidth, 0.35)];
                            lineLabel1.backgroundColor=qianhuicolor;
                            [shangpingView addSubview:lineLabel1];
                        }else{
                            UILabel *lineLabel1=[[UILabel alloc] initWithFrame:CGRectMake(15, 120-0.35, ScreenWidth-30, 0.35)];
                            lineLabel1.backgroundColor=qianhuicolor;
                            [shangpingView addSubview:lineLabel1];
                            
                            
                        }
                        
                        [view addSubview:shangpingView];
                        
                    }
                    
                }
                
                
                
                lineLab1=[[UILabel alloc] initWithFrame:CGRectMake(0, shangpingView.bottom+10-0.35, ScreenWidth, 0.35)];
                lineLab1.backgroundColor=qianhuicolor;
                [view addSubview:lineLab1];
                
                
                shoukuanxinxi=[[UILabel alloc]initWithFrame:CGRectMake(0, shangpingView.bottom+10, ScreenWidth, 45)];
                shoukuanxinxi.text=@"    收款信息";
                shoukuanxinxi.textColor=[UIColor blackColor];
                shoukuanxinxi.layer.borderColor = LineColor.CGColor;
                shoukuanxinxi.backgroundColor=[UIColor whiteColor];
                shoukuanxinxi.font=[UIFont systemFontOfSize:15];
                [view addSubview:shoukuanxinxi];
                
                view.frame=CGRectMake(0, 0, ScreenWidth, shoukuanxinxi.bottom);
                _table.tableHeaderView=view;
                
                
                
                [self jiazaiyouhuiquan];
                //shoukuan
                
                
                
                
                
                
                
                MYmainScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0, ScreenWidth, ScreenHeight)];
                [MYmainScroll setBackgroundColor: zuiqianhuicolor];
                
                MYmainScroll.delegate = self;
                MYmainScroll.userInteractionEnabled = YES;
                MYmainScroll.scrollEnabled = YES;
                MYmainScroll.showsVerticalScrollIndicator = FALSE;
                MYmainScroll.showsHorizontalScrollIndicator = FALSE;
                [self.view addSubview:MYmainScroll];
                
                
                view4=[[UIView alloc]initWithFrame:CGRectMake(0,0, ScreenWidth, 200)];
                view4.backgroundColor=[UIColor whiteColor];
                [MYmainScroll addSubview:view4];
                
                UILabel *lineLabel12=[[UILabel alloc] initWithFrame:CGRectMake(15, 90-0.35, ScreenWidth-30, 0.35)];
                lineLabel12.backgroundColor=qianhuicolor;
                [view4 addSubview:lineLabel12];
                UILabel *lineLabel112=[[UILabel alloc] initWithFrame:CGRectMake(15, 135-0.35, ScreenWidth-30, 0.35)];
                lineLabel112.backgroundColor=qianhuicolor;
                [view4 addSubview:lineLabel112];
                UILabel *lineLabel13=[[UILabel alloc] initWithFrame:CGRectMake(0, 200-0.35, ScreenWidth, 0.35)];
                lineLabel13.backgroundColor=qianhuicolor;
                [view4 addSubview:lineLabel13];
                
                
                
                UIImageView *_xianview = [[UIImageView alloc]initWithFrame:CGRectMake(15,0, ScreenWidth-30, 0.5)];
                _xianview.image=[UIImage imageNamed:@"hengxian"];
                [view4 addSubview:_xianview];
                UIImageView *_xianview1 = [[UIImageView alloc]initWithFrame:CGRectMake(15,45, ScreenWidth-30, 0.5)];
                _xianview1.image=[UIImage imageNamed:@"hengxian"];
                [view4 addSubview:_xianview1];
                
                
                
                
                zhekoujineTextFied=[[UITextField alloc]initWithFrame:CGRectMake(15,0, ScreenWidth-100,45)];
                zhekoujineTextFied.borderStyle = UITextBorderStyleNone;
                zhekoujineTextFied.keyboardType = UIKeyboardTypeDecimalPad;
                zhekoujineTextFied.font = [UIFont systemFontOfSize: contenfot];
                zhekoujineTextFied.textColor=[UIColor blackColor];
                zhekoujineTextFied.autocapitalizationType = UITextAutocapitalizationTypeSentences;
                zhekoujineTextFied.tag=1;
                [zhekoujineTextFied addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
                zhekoujineTextFied.placeholder = @"请输入整单折扣金额"; //默认显示的字
                zhekoujineTextFied.delegate = self;
                [zhekoujineTextFied setUserInteractionEnabled:YES];
                zhekoujineTextFied.clearButtonMode = UITextFieldViewModeWhileEditing;
                [view4 addSubview:zhekoujineTextFied];
                zhekoujineTextFied.inputAccessoryView = myToolBar;
                
                
                
                youhuijine=[[UILabel alloc]initWithFrame:CGRectMake(15, 45, ScreenWidth-40, 45)];
                youhuijine.text=[NSString stringWithFormat:@"优惠后金额¥%@" ,formattedNumberString];
                youhuijine.textColor=[UIColor blackColor];
                youhuijine.textAlignment = NSTextAlignmentRight;
                NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"优惠后金额 ¥ %@" ,formattedNumberString]];
                
                [AttributedStr addAttribute:NSFontAttributeName
                 
                                      value:[UIFont systemFontOfSize:13.0]
                 
                                      range:NSMakeRange(0, 8)];
                
                [AttributedStr addAttribute:NSForegroundColorAttributeName
                 
                                      value:zhonghuiColor
                 
                                      range:NSMakeRange(0, 8)];
                
                
                youhuijine.attributedText = AttributedStr;
                
                [view4 addSubview:youhuijine];
                
                
                
                UILabel*shifou=[[UILabel alloc]initWithFrame:CGRectMake(15, 87.5, 80, 50)];
                shifou.text=@"是否定金";
                shifou.textColor=shenhuicolor;
                shifou.font=[UIFont systemFontOfSize:14];
                [view4 addSubview:shifou];
                
                
                switch2 = [[ZJSwitch alloc] initWithFrame:CGRectMake(ScreenWidth-75, 97.5, 55, ScreenHeight*15/1334)];
                switch2.onTintColor=luseColor;
                switch2.onText = @"是";
                switch2.offText = @"";
                switch2.on = NO;
                
                [switch2 addTarget:self action:@selector(switchAction1:) forControlEvents:UIControlEventValueChanged];
                [view4 addSubview:switch2];
                
                
                
                
                dinjinjineTextFied=[[UITextField alloc]initWithFrame:CGRectMake(15,140, ScreenWidth-100,50)];
                dinjinjineTextFied.borderStyle = UITextBorderStyleNone;
                dinjinjineTextFied.keyboardType = UIKeyboardTypeDecimalPad;
                dinjinjineTextFied.font = [UIFont systemFontOfSize: contenfot];
                dinjinjineTextFied.textColor=[UIColor blackColor];
                dinjinjineTextFied.autocapitalizationType = UITextAutocapitalizationTypeSentences;
                dinjinjineTextFied.tag=2;
                [dinjinjineTextFied addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
                dinjinjineTextFied.placeholder = @"请输入定金金额"; //默认显示的字
                dinjinjineTextFied.delegate = self;
                [dinjinjineTextFied setUserInteractionEnabled:NO];
                dinjinjineTextFied.clearButtonMode = UITextFieldViewModeWhileEditing;
                [view4 addSubview:dinjinjineTextFied];
                dinjinjineTextFied.inputAccessoryView = myToolBar;
                
                
                
                
                
                //加载配送界面
                
                view5=[[UIView alloc]initWithFrame:CGRectMake(0, view4.bottom+10, ScreenWidth, 50)];
                view5.backgroundColor=[UIColor whiteColor];
                view5.layer.borderWidth = 0.35;
                view5.layer.borderColor = qianhuicolor.CGColor;
                [MYmainScroll addSubview:view5];
                
                
                UILabel*fangshi=[[UILabel alloc]initWithFrame:CGRectMake(15, 0, 80, 50)];
                fangshi.text=@"配送方式";
                fangshi.textColor=shenhuicolor;
                fangshi.font=[UIFont systemFontOfSize:14];
                [view5 addSubview:fangshi];

    
                
                view6=[[UIView alloc]initWithFrame:CGRectMake(0, view5.bottom+10, ScreenWidth, 120)];
                view6.backgroundColor=[UIColor whiteColor];
                view6.layer.borderWidth = 0.35;
                view6.layer.borderColor = qianhuicolor.CGColor;
                [MYmainScroll addSubview:view6];
    
                tv=[[UITextView alloc]init];
                tv.frame=CGRectMake(20, 10, ScreenWidth-40, 90);
                tv.backgroundColor = [UIColor whiteColor];//设置它的背景颜色/Users/jiezsoft/Desktop/
                tv.scrollEnabled = YES;//是否可以拖动
                tv.delegate=self;
                tv.font = [UIFont fontWithName:@"Arial" size:15.0];//设置字体名字和字体大小
                tv.layer.borderWidth =0.0;
                CGColorSpaceRef registedSpace11 = CGColorSpaceCreateDeviceRGB();
                CGColorRef tureBTncolorref111 = CGColorCreate(registedSpace11,(CGFloat[]){ 0, 0, 0, 0.3 });
                //                tv.keyboardType = UIKeyboardTypePhonePad;
                [tv.layer setBorderColor:tureBTncolorref111];//边框颜色
                tv.layer.cornerRadius =0;
                [view6 addSubview:tv];
                imagess=[[UIImageView alloc]initWithFrame:CGRectMake(0, 5,18, 16)];
                imagess.image=[UIImage imageNamed:@"_0000_xingxifankui.png"];
                [tv addSubview:imagess];
                label=[[UILabel alloc]init];
                label.frame =CGRectMake(23, 7, ScreenWidth-60, 14);
                label.text = @"备注";
                label.textColor=zuiqianhuicolor;
                label.numberOfLines=0;
                label.font=[UIFont systemFontOfSize:14];
                label.enabled = NO;//lable必须设置为不可用
                label.backgroundColor = [UIColor clearColor];
                [tv addSubview:label];
                
                tv.inputAccessoryView = myToolBar;
                [self jiazaileibieDiscountRate];
                [self jiazaileibieEarnestRate];
//              [self jiazaileibieAnzhuang];
                [self jiazaileibiePeisong];
    
                
                
                _table.tableFooterView=MYmainScroll;
   
                
                hejiMoney=[[UIButton alloc]initWithFrame:CGRectMake(0, ScreenHeight-48, ScreenWidth*430/750, 48)];
                hejiMoney.backgroundColor=[UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:1.0];
                hejiMoney.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft;
                [hejiMoney setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
                hejiMoney.alpha=0.8;
                [self priceStr:formattedNumberString];
                [self.view addSubview:hejiMoney];
    
                UIButton*buyBtn2=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth*430/750, ScreenHeight-48, ScreenWidth*320/750, 48)];
                [buyBtn2 setTitle:@"去收银" forState:UIControlStateNormal];
                buyBtn2.backgroundColor=luseColor;
                [buyBtn2 addTarget:self action:@selector(shouying:) forControlEvents:UIControlEventTouchUpInside];
                
                [buyBtn2 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
                [self.view addSubview:buyBtn2];
                
                
                
    
    
    
}



-(void)priceStr:(NSString *)str {
    
     [hejiMoney setTitle:[NSString stringWithFormat:@"  金额 ￥%@",str] forState:UIControlStateNormal];
        NSMutableAttributedString *AttributedStr1 = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"  金额 ￥%@",str]];
    
    [AttributedStr1 addAttribute:NSFontAttributeName
     
                           value:[UIFont systemFontOfSize:14.0]
     
                           range:NSMakeRange(0, 6)];
    
    [AttributedStr1 addAttribute:NSForegroundColorAttributeName
     
                           value:[UIColor whiteColor]
     
                           range:NSMakeRange(0, 6)];
    
    
    hejiMoney.titleLabel.attributedText = AttributedStr1;
    
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [couponId count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    
    shouyinCell* cell = (shouyinCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
    {
        NSArray* nib = [[NSBundle mainBundle] loadNibNamed:@"shouyinCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
    }
    UIButton*jiantou = [[UIButton alloc]init];
    jiantou.frame = CGRectMake(0,0, 8, 13);
    [jiantou setImage:[UIImage imageNamed:@"xiangzuo-.png"] forState:UIControlStateNormal];
    
    //    cell.accessoryView = jiantou;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    cell.saveAccount=YES;
    
    
    cell.title.text =[NSString stringWithFormat:@"%@ ¥ %@",[title objectAtIndex:indexPath.row],[price objectAtIndex:indexPath.row]];
    cell.title.font=[UIFont systemFontOfSize:15];
    cell.title.textColor=zhonghuiColor;
    NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@ ¥ %@",[title objectAtIndex:indexPath.row],[price objectAtIndex:indexPath.row]]];
    NSInteger count = [[title objectAtIndex:indexPath.row]length];
    NSString *string=[NSString stringWithFormat:@"%@",[price objectAtIndex:indexPath.row]];
    NSInteger count1 =[string length];
    [AttributedStr addAttribute:NSFontAttributeName
     
                          value:[UIFont systemFontOfSize:16.0]
     
                          range:NSMakeRange(count, count1+3)];
    
    [AttributedStr addAttribute:NSForegroundColorAttributeName
     
                          value:hongsecolor
     
                          range:NSMakeRange(count, count1+3)];
    
    
    cell.title.attributedText = AttributedStr;
    
    
    
    
    
    
    
    [cell.xuanzeBtn addTarget:self action:@selector(xiangqing:) forControlEvents:UIControlEventTouchUpInside];
    cell.xuanzeBtn.tag=indexPath.row;
    
    
    
    
    if  ([couponIds containsObject:[couponId objectAtIndex:indexPath.row]]){
        
        
        cell.xuanzeimage.image=[UIImage imageNamed:@"gous"];
        cell.saveAccount=NO;
        
    }
    
    
    if (couponId.count !=indexPath.row+1) {
        UIImageView *_xianview = [[UIImageView alloc]initWithFrame:CGRectMake(15,0, ScreenWidth-30, 0.5)];
        _xianview.image=[UIImage imageNamed:@"hengxian"];
        [cell.contentView addSubview:_xianview];
        
    }
    
    if (indexPath.row==0) {
        UILabel *lineLabel31=[[UILabel alloc] initWithFrame:CGRectMake(15, 0, ScreenWidth-30, 0.35)];
        lineLabel31.backgroundColor=qianhuicolor;
        [cell.contentView addSubview:lineLabel31];
        
    }
    
    return cell;
    
    
}

- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    return  45;
}


#pragma mark - Table view delegate



- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
    
    UITableViewCell *cell=[tableView cellForRowAtIndexPath:indexPath];
    shouyinCell *sharecell=(shouyinCell *)cell;
    sharecell.saveAccount=! sharecell.saveAccount;
    
    if (!sharecell.saveAccount) {
        [couponIds addObject:[NSString stringWithFormat:@"%@",[couponId objectAtIndex:indexPath.row]]];
        [prices addObject:[NSString stringWithFormat:@"%@",[price objectAtIndex:indexPath.row]]];
        
        
        UITableViewCell *cell=[tableView cellForRowAtIndexPath:indexPath];
        shouyinCell *sharecell=(shouyinCell *)cell;
        sharecell.xuanzeimage.image=[UIImage imageNamed:@"gous"];
        
        
        double d1;
        NSNumber *sum = [prices valueForKeyPath:@"@sum.floatValue"];
        double d2;
        double d3;
        d1=sum.doubleValue;
        d2=totalMoney.doubleValue;
        d3=zhekoujineTextFied.text.doubleValue;
        
        
        [self youhuijiehouduoshao:[NSString stringWithFormat:@"%.2f",d2-d1-d3]];
        
        [self heji];
        
        
        
    }
    else{
        UITableViewCell *cell=[tableView cellForRowAtIndexPath:indexPath];
        shouyinCell *sharecell=(shouyinCell *)cell;
        
        sharecell.xuanzeimage.image=[UIImage imageNamed:@"quans"];
        if (couponIds.count>0) {
            
            for (int i=0; i<couponIds.count; i++) {
                
                NSString *codeStr = [couponIds objectAtIndex:i];
                if ([codeStr isEqualToString:[NSString stringWithFormat:@"%@",[couponId objectAtIndex:indexPath.row]]] ) {
                    
                    [couponIds removeObjectAtIndex:i];//从指定索引移除
                    [prices removeObjectAtIndex:i];//从指定索引移除
                    
                    
                }
                
                
                
                double d1;
                NSNumber *sum = [prices valueForKeyPath:@"@sum.floatValue"];
                double d2;
                double d3;
                d1=sum.doubleValue;
                d2=totalMoney.doubleValue;
                d3=zhekoujineTextFied.text.doubleValue;
                
                
                [self youhuijiehouduoshao:[NSString stringWithFormat:@"%.2f",d2-d1-d3]];
                
                [self heji];
                
            }
        }
    }
    
    
    
    
 
    
}






- (void)dateChanged:(id)sender
{
    
    UIDatePicker* picker = (UIDatePicker*)sender;
    NSDateFormatter* df = [[NSDateFormatter alloc] init];
    [df setDateFormat:@"yyyy-MM-dd HH:mm"];
    
    if ([songhuoTextFied isFirstResponder])
    {
        songhuoTextFied.text = [NSString stringWithFormat:@"%@", [df stringFromDate:picker.date]];
        
        
        
    }else{
        
        anzhuangTextFied.text = [NSString stringWithFormat:@"%@", [df stringFromDate:picker.date]];
    }
    
    
}

-(void)switchAction1:(UISwitch*)sender{
    
    if (sender.on ==YES) {
        self.isEarnest=@"Y";
        [self heji];
        [dinjinjineTextFied setUserInteractionEnabled:YES];
    }
    
    if (sender.on == NO) {
        
        self.isEarnest=@"N";
        [self heji];
        [dinjinjineTextFied setUserInteractionEnabled:NO];
    }
}

-(void)xiangqing:(UIButton*)sender{
    
    
    commdity.actTypeCode=couponId [sender.tag];
    
    
    
    BusinessCouponDetailViewController *detailViewController = [[BusinessCouponDetailViewController alloc] init];
    
    [self.navigationController pushViewController:detailViewController animated:YES];
    
    
    
    
    
}

-(void)zhekoujineBTn:(UIButton *)sender {
    
}
-(void)list:(UIButton*)sender{
    
    huiyuandengjiViewController *detailViewController = [[huiyuandengjiViewController alloc] init];
    commdity.addhuiyuanViewController=@"选择";
    detailViewController.delegate = self;
    [self.navigationController pushViewController:detailViewController animated:YES];
    
    
}
-(void)edithuiyuan1:(UIButton*)sender{
    commdity.addhuiyuanViewController=@"选择";
    BusinessMemberAddressViewController *detailViewController = [[BusinessMemberAddressViewController alloc] init];
    
    [self.navigationController pushViewController:detailViewController animated:YES];
    
    
}
-(void)edithuiyuan:(UIButton*)sender{
    commdity.gengxin=@"";
    huiyuanDetailsViewController *detailViewController = [[huiyuanDetailsViewController alloc] init];
    
    [self.navigationController pushViewController:detailViewController animated:YES];
    
    
}

-(void)addhuiyuan1:(UIButton*)sender{
    
    addhuiyuanViewController *detailViewController = [[addhuiyuanViewController alloc] init];
    
    [self.navigationController pushViewController:detailViewController animated:YES];
    
    
}



//1   加载自定义类别   订单折扣百分比 DiscountRate／／／／／／订单定金百分比 EarnestRate／／／／／／／／／／／／／／／／／／／／／／／／／
-(void)DiscountRateSatBtn:(UIButton *)sender {
    [dinjinjineTextFied resignFirstResponder];
    [anzhuangTextFied resignFirstResponder];
    [songhuoTextFied resignFirstResponder];
    [tv resignFirstResponder];
    [zhekoujineTextFied resignFirstResponder];
    commdity.leibeicode=DiscountRatecode;
    commdity.leibeicontent=DiscountRatecontent;
    commdity.sat=@"DiscountRate";
    peisongleibieViewController*de = [[peisongleibieViewController alloc] init];
    
    [self.navigationController pushViewController:de animated:YES];
    
    
    
}


-(void)EarnestRateSatBtn:(UIButton *)sender {
    [dinjinjineTextFied resignFirstResponder];
    [anzhuangTextFied resignFirstResponder];
    [songhuoTextFied resignFirstResponder];
    [tv resignFirstResponder];
    [zhekoujineTextFied resignFirstResponder];
    commdity.leibeicode=EarnestRatecode;
    commdity.leibeicontent=EarnestRatecontent;
    
    commdity.sat=@"EarnestRate";
    
    switch2.on = YES;
    self.isEarnest=@"Y";
    [dinjinjineTextFied setUserInteractionEnabled:YES];
    [self heji];
    peisongleibieViewController*de = [[peisongleibieViewController alloc] init];
    
    [self.navigationController pushViewController:de animated:YES];
    
    
    
    
}


-(void)jiazaileibieEarnestRate{
    
    
    
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString* Token = [user objectForKey:@"tokenId"];
    if (Token ==nil) {
        Token=@"dd";
    }
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setValue:Token forKey:@"tokenId"];
    [param setValue:@"EarnestRate" forKey:@"optionName"];
    
    
    
    [HttpRequest requestData:@"System/AppCodes" params:param success:^(BOOL isSuccess, SeverData *severDataDict) {
        if (isSuccess) {
            
            NSLog(@"====%@",severDataDict.dataDict);
            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                [Global hideProgressHUDInternal:self.view];
                
                NSMutableArray* arrr=[[NSMutableArray alloc]init];
                arrr=[severDataDict.dataDict objectForKey:@"DataLine"];
                for (NSDictionary* dicc in arrr )
                {
                    [EarnestRatecode addObject:[dicc valueForKey:@"code"]];
                    [EarnestRatecontent addObject:[dicc valueForKey:@"content"]];
                    
                    
                }
                
                EarnestRateSatBtn=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth-100, 225-85, 60,50)];
                EarnestRateSatBtn.titleLabel.font=[UIFont systemFontOfSize:contenfot];
                EarnestRateSatBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
                [EarnestRateSatBtn addTarget:self action:@selector(EarnestRateSatBtn:) forControlEvents:UIControlEventTouchUpInside];
                [EarnestRateSatBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
                [view4 addSubview:EarnestRateSatBtn];
                jiantouBtn1 = [[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth-30,245-86,46/3, 25/3)];
                [jiantouBtn1 setImage:[UIImage imageNamed:@"xiangxia-"] forState:UIControlStateNormal];
                [jiantouBtn1 addTarget:self action:@selector(EarnestRateSatBtn:) forControlEvents:UIControlEventTouchUpInside];
                [view4 addSubview:jiantouBtn1];
                [EarnestRateSatBtn setTitle:EarnestRatecontent[0] forState:UIControlStateNormal];
                commdity.EarnestRatecode=EarnestRatecode[0];
            }else{
                [Global hideProgressHUDInternal:self.view];
                NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                // [Global showTextHud:requestResultStr view:self.view];
                [Global showTextHudSub:requestResultStr view:self.view];
            }
            
        }
        else
        {
            [Global hideProgressHUDInternal:self.view];
            
            [Global showTextHudSub:@"连接失败" view:self.view];
        }
        
    }];
    
    
    
}

-(void)jiazaileibieDiscountRate{
    
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString* Token = [user objectForKey:@"tokenId"];
    if (Token ==nil) {
        Token=@"dd";
    }
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setValue:Token forKey:@"tokenId"];
    [param setValue:@"DiscountRate" forKey:@"optionName"];
    
    [HttpRequest requestData:@"System/AppCodes" params:param success:^(BOOL isSuccess, SeverData *severDataDict) {
        if (isSuccess) {
            
            NSLog(@"====%@",severDataDict.dataDict);
            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                [Global hideProgressHUDInternal:self.view];
                
                NSMutableArray* arrr=[[NSMutableArray alloc]init];
                arrr=[severDataDict.dataDict objectForKey:@"DataLine"];
                for (NSDictionary* dicc in arrr )
                {
                    [DiscountRatecode addObject:[dicc valueForKey:@"code"]];
                    [DiscountRatecontent addObject:[dicc valueForKey:@"content"]];
                    
                    
                }
                
                
                DiscountRateSatBtn=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth-100,  0, 60,50)];
                DiscountRateSatBtn.titleLabel.font=[UIFont systemFontOfSize:contenfot];
                DiscountRateSatBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
                [DiscountRateSatBtn addTarget:self action:@selector(DiscountRateSatBtn:) forControlEvents:UIControlEventTouchUpInside];
                [DiscountRateSatBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
                [view4 addSubview:DiscountRateSatBtn];
                jiantouBtn = [[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth-30,110-90,46/3, 25/3)];
                [jiantouBtn setImage:[UIImage imageNamed:@"xiangxia-"] forState:UIControlStateNormal];
                [jiantouBtn addTarget:self action:@selector(DiscountRateSatBtn:) forControlEvents:UIControlEventTouchUpInside];
                [view4 addSubview:jiantouBtn];
                
                
                commdity.DiscountRatecode=DiscountRatecode[0];
                [DiscountRateSatBtn setTitle:DiscountRatecontent[0] forState:UIControlStateNormal];
                
            }else{
                [Global hideProgressHUDInternal:self.view];
                NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                // [Global showTextHud:requestResultStr view:self.view];
                [Global showTextHudSub:requestResultStr view:self.view];
            }
            
        }
        else
        {
            [Global hideProgressHUDInternal:self.view];
            
            [Global showTextHudSub:@"连接失败" view:self.view];
        }
        
    }];
    
    
    
}

-(void)shouying:(UIButton *)sender {
    
    
    
    if ([self.memberId length] <1)
    {
        [self showAlertMessage:@"请选择会员信息"];
    }
    else{
        
        if ([commdity.adress length] <1)
        {
            [self showAlertMessage:@"地址不能为空！"];
        }
        else{
            
            NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
            NSString* Token = [user objectForKey:@"tokenId"];
            if (Token ==nil) {
                Token=@"dd";
            }
            
            NSMutableDictionary *params = [NSMutableDictionary new];
            [params setValue:Token forKey:@"tokenId"];
            [params setValue:commdity.userName forKey:@"memberName"];
            [params setValue:self.memberId forKey:@"memberId"];
            [params setValue:commdity.DeliveryTypecode forKey:@"deliveryType"];
//            [params setValue:songhuoTextFied.text forKey:@"deliveryDate"];
//            [params setValue:commdity.InstallTypecode forKey:@"installType"];
//            [params setValue:anzhuangTextFied.text forKey:@"installDate"];
            
            [params setValue:couponIds forKey:@"couponIds"];
            [params setValue:[prices valueForKeyPath:@"@sum.floatValue"] forKey:@"couponMoney"];//优惠券金额
            [params setValue:[NSString stringWithFormat:@"%.2f",  zhekoujineTextFied.text.doubleValue]   forKey:@"discountMoney"];//discountMoney
            [params setValue:self.isEarnest  forKey:@"isEarnest"];
            [params setValue:[NSString stringWithFormat:@"%.2f",  dinjinjineTextFied.text.doubleValue]   forKey:@"earnestMoney"];//earnestMoney
            [params setValue:commdity.adress forKey:@"address"];
            [params setValue:commdity.userName forKey:@"consignee"];
            [params setValue:commdity.Phone forKey:@"phone"];
            [params setValue:tv.text  forKey:@"remark"];
            
            
            NSMutableArray *mDocumentLine=[NSMutableArray array];
            
            
            for (int i=0; i<self.itemCodeArray.count; i++) {
                
                NSMutableDictionary *dic = [NSMutableDictionary dictionary];
                NSString *itemId = [self.itemIdArray objectAtIndex:i];
                NSString *quantity =[self.quantityArray objectAtIndex:i];
//              NSString *specId = [self.specIdArray objectAtIndex:i];
                
                NSString *specId =[NSString stringWithFormat:@"%@",[self.specIdArray objectAtIndex:i]];

                NSString *dealPrice = [self.dealPriceArray objectAtIndex:i];

                
                [dic setValue:quantity forKey:@"quantity"];
                [dic setValue:itemId forKey:@"itemId"];
                [dic setValue:dealPrice forKey:@"dealPrice"];
               
                if ([specId isEqualToString:@""]) {
                    
                }else{
                    
                    if ([specId isEqualToString:@"<null>"]) {
                        specId=@"";
                    }
                    [dic setValue:specId forKey:@"specId"];
                }
                
                [mDocumentLine addObject:dic];
                
                
            }

            
            
            [params setValue:mDocumentLine  forKey:@"items"];
            
            
            
            
            NSLog(@"33333333====%@",params);
            
            
            [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
            
            
            [HttpRequest requestData:@"Business/Order/ExtAdd" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
                if (isSuccess) {
                    
                    NSLog(@"33333333====%@",severDataDict.dataDict);
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                        [Global hideProgressHUDInternal:self.view];
                        
                        [Global hideProgressHUDInternal:self.view];
                        NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                        [Global showTextHudSub:requestResultStr view:self.view];
                        
                       
                        
                         [ClearFB clearUserData:userToken typeString:_saveTypeStr];
                        
                        commdity.userName=nil,commdity.Phone=nil;
                        commdity.Dict=severDataDict.dataDict;
                        commdity.sat=@"shouyin";
                        commdity.Dicts=nil;
                        ToResiduePayViewController  *generateVC=[[ToResiduePayViewController alloc] init];
                        [self.navigationController pushViewController:generateVC animated:YES];
                        
                        
                        
                       
                    }else{
                        [Global hideProgressHUDInternal:self.view];
                        NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                        // [Global showTextHud:requestResultStr view:self.view];
                        [Global showTextHudSub:requestResultStr view:self.view];
                    }
                    
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    
                    [Global showTextHudSub:@"连接失败" view:self.view];
                }
                
            }];
            
        }
    }
    
}



//  2   加载类别／／／／／／／／／／／／／／／／／／／／／／／／／／／／／／／
-(void)anzhuangSatBtn:(UIButton *)sender {
    [dinjinjineTextFied resignFirstResponder];
    [anzhuangTextFied resignFirstResponder];
    [songhuoTextFied resignFirstResponder];
    [tv resignFirstResponder];
    [zhekoujineTextFied resignFirstResponder];
    commdity.leibeicode=InstallTypecode;
    commdity.leibeicontent=InstallTypecontent;
    commdity.sat=@"InstallType";
    peisongleibieViewController*de = [[peisongleibieViewController alloc] init];
    
    [self.navigationController pushViewController:de animated:YES];
    
    
    
}
-(void)saoyisao:(UIButton *)sender {
    
    commdity.sat=@"HUIyuan";
    saoyisaoViewController*de = [[saoyisaoViewController alloc] init];
    
    [self.navigationController pushViewController:de animated:YES];
}
-(void)peisongSatBtn:(UIButton *)sender {
    [dinjinjineTextFied resignFirstResponder];
    [anzhuangTextFied resignFirstResponder];
    [songhuoTextFied resignFirstResponder];
    [tv resignFirstResponder];
    [zhekoujineTextFied resignFirstResponder];
    commdity.leibeicode=DeliveryTypecode;
    commdity.leibeicontent=DeliveryTypecontent;
    
    commdity.sat=@"DeliveryType";
    peisongleibieViewController*de = [[peisongleibieViewController alloc] init];
    
    [self.navigationController pushViewController:de animated:YES];
    
    
}





-(void)jiazaileibiePeisong{
    
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString* Token = [user objectForKey:@"tokenId"];
    if (Token ==nil) {
        Token=@"dd";
    }
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setValue:Token forKey:@"tokenId"];
    [param setValue:@"DeliveryType" forKey:@"optionName"];
    
    [HttpRequest requestData:@"System/AppCodes" params:param success:^(BOOL isSuccess, SeverData *severDataDict) {
        if (isSuccess) {
            
            NSLog(@"====%@",severDataDict.dataDict);
            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                [Global hideProgressHUDInternal:self.view];
                
                NSMutableArray* arrr=[[NSMutableArray alloc]init];
                arrr=[severDataDict.dataDict objectForKey:@"DataLine"];
                for (NSDictionary* dicc in arrr )
                {
                    [DeliveryTypecode addObject:[dicc valueForKey:@"code"]];
                    [DeliveryTypecontent addObject:[dicc valueForKey:@"content"]];
                    
                    
                }
                
                
                peisongSatBtn=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth/2-20,  0, ScreenWidth/2-20,50)];
                peisongSatBtn.titleLabel.font=[UIFont systemFontOfSize:contenfot];
                peisongSatBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
                [peisongSatBtn addTarget:self action:@selector(peisongSatBtn:) forControlEvents:UIControlEventTouchUpInside];
                [peisongSatBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
                [view5 addSubview:peisongSatBtn];
                jiantouBtn = [[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth-30,20,46/3, 25/3)];
                [jiantouBtn setImage:[UIImage imageNamed:@"xiangxia-"] forState:UIControlStateNormal];
                [jiantouBtn addTarget:self action:@selector(peisongSatBtn:) forControlEvents:UIControlEventTouchUpInside];
                [view5 addSubview:jiantouBtn];
                
                
                commdity.DeliveryTypecode=DeliveryTypecode[0];
                [peisongSatBtn setTitle:DeliveryTypecontent[0] forState:UIControlStateNormal];
                
            }else{
                [Global hideProgressHUDInternal:self.view];
                NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                // [Global showTextHud:requestResultStr view:self.view];
                [Global showTextHudSub:requestResultStr view:self.view];
            }
            
        }
        else
        {
            [Global hideProgressHUDInternal:self.view];
            
            [Global showTextHudSub:@"连接失败" view:self.view];
        }
        
    }];
    
    
    
}


- (BOOL)textViewShouldBeginEditing:(UITextView *)textView{
    
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    _table .frame =CGRectMake(0, -200, ScreenWidth, ScreenHeight);
    [UIView commitAnimations];
    
    return self;
}

-(void)textViewDidChange:(UITextView *)textView
{
    //self.examineText =  textView.text;
    
    
    if (textView.text.length == 0) {
        [imagess removeFromSuperview];
        
        imagess=[[UIImageView alloc]initWithFrame:CGRectMake(0, 5, 18, 16)];
        imagess.image=[UIImage imageNamed:@"_0000_xingxifankui.png"];
        [tv addSubview:imagess];
        label.text = @"备注";
        
    }else{
        [imagess removeFromSuperview];
        label.text = @"";
    }
}


//回收键盘
-(void)OnTapDone{
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    _table .frame =CGRectMake(0, 0, ScreenWidth, ScreenHeight);
    [UIView commitAnimations];
    [                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 dinjinjineTextFied resignFirstResponder];
    [anzhuangTextFied resignFirstResponder];
    [songhuoTextFied resignFirstResponder];
    [tv resignFirstResponder];
    [zhekoujineTextFied resignFirstResponder];
}
-(void)closeKeyBoad
{
    
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    _table .frame =CGRectMake(0, 0, ScreenWidth, ScreenHeight);
    [UIView commitAnimations];
    [dinjinjineTextFied resignFirstResponder];
    [anzhuangTextFied resignFirstResponder];
    [songhuoTextFied resignFirstResponder];
    [tv resignFirstResponder];
    [zhekoujineTextFied resignFirstResponder];
}

- (void)showAlertWait
{
    alt = [[UIAlertView alloc] initWithTitle:@"网络不稳定 ！" message:@"请确认网络" delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
    
}

- (void)showAlertMessage:(NSString *)msg
{
    alt = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:msg delegate:nil cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
}
- (void)hideAlert
{
    if (alt != nil)
    {
        [alt dismissWithClickedButtonIndex:0 animated:YES];
        alt = nil;
    }
}


@end
